Skip to content

Wait for a lagging Cloudflare Worker version list during deploy - #892

Open
konaito wants to merge 4 commits into
voidzero-dev:mainfrom
konaito:fix/retry-stale-cloudflare-version-history
Open

konaito wants to merge 4 commits into
voidzero-dev:mainfrom
konaito:fix/retry-stale-cloudflare-version-history

Conversation

@konaito

@konaito konaito commented Nov 21, 2026 •

Copy link
Copy Markdown

Fixes #891 for the version-list paths. The triggers-failed case in the issue is not changed here.

Change

Cloudflare's Worker version list can trail a write by minutes. The deploy now waits for it in the two places where the expected state is known:

  • Before the upload: while the list does not contain the active version that deployments status reported. This read had no retry.
  • After the upload: while the list is still identical to the pre-upload baseline. The existing retry stopped after 250 ms and 500 ms.
  • Both places: when versions.list fails because its two pages disagreed ("The Cloudflare Worker version history changed during inspection"). The runner now marks that failure as version-history-changed, and it is retried on the same schedule. Page 2 is read only above 10 versions, so this is the inheritance-source-unavailable shape in the second report on Cloudflare deploy stops on a lagging Worker version list (inheritance-source-changed, triggers-failed) #891.

After either wait, production is read again: before the upload, and before the candidate receipt is saved. If a rollback or another deploy changed it during the wait, the deploy stops with deployment-changed and saves no receipt, so the next deploy does not find a receipt with the wrong parent. Production is read again only after a wait.

These waits use STALE_VERSION_HISTORY_DELAYS_MS: 250 ms doubling up to 30 s, 17 waits, about 5.5 minutes in total. Each wait checks verifyUploader() and the first one reports progress. The schedule can be overridden with the new versionHistoryRetryDelaysMs option. STALE_VERSION_HISTORY_DELAYS_MS is exported from the package entry.

Why this length: in the runs in #891 a new version was still missing 52 s after creation and was listed within about 4.5 minutes. #880 and #868 retried for a second or less, which does not reach that. If maintainers want a shorter cap, change the constant.

What does not change

  • A list that never catches up, or whose pages keep disagreeing, still fails with the same reasons (inheritance-source-changed before the upload, inheritance-source-unavailable after it). Nothing is uploaded when the pre-upload wait runs out.
  • Any other mismatch (a concurrent version, a different history) still fails at once, with no wait.
  • Any other failed read (not stale, not page overlap) keeps its behavior: it fails at once before the upload and gets two quick retries after it.
  • A rollback to a version older than the list's page of 10 never appears in the list, so it does not wait. Before waiting, the active version's number is read with versions.view; the wait happens only when that number is not below the list's lowest number. If the number cannot be read (failed or thrown read, or no integer number; the API marks the field optional), the deploy waits as for a lagging list, since a version the list trails may not be readable yet either.
  • stabilizeCloudflareVersionTriggers is untouched. The logs in Cloudflare deploy stops on a lagging Worker version list (inheritance-source-changed, triggers-failed) #891 do not show what its reads returned.

Tests

packages/deploy-cloudflare/test/unit/version.test.ts:

  • Pre-upload: active version present (no wait), list recovers after two stale reads, list never catches up (no upload), uploader changes during the wait.
  • Page overlap: retried and recovers, retried until the schedule runs out, and a different failure does not wait, before and after the upload. The runner test in packages/void/test/unit/cf-version-runner.test.ts checks the version-history-changed marker.
  • Post-upload: the existing stale-list cases now expect the full schedule; failed reads still expect two waits.
  • The default schedule is used, is between 5 and 6 minutes, and reports progress.
  • A rollback during the wait, before and after the upload: the deploy stops with deployment-changed, and recordVerifiedCandidate is never called.
  • An active version older than ten listed versions does not wait. A failed, thrown or unnumbered versions.view still waits the whole schedule.

The new pre-upload tests and the changed stale-list case fail on main and pass here (5 failures without the change; measured before the page-overlap commit).

Verified locally

Run in a shell with no CLOUDFLARE_*, CF_* or wrangler variables (env | grep -ciE 'cloudflare|^CF_|wrangler' printed 0). The tests inject runWrangler, so no cf or wrangler process starts.

  • vp test run packages/deploy-cloudflare/test/unit/version.test.ts: 237 passed after the page-overlap commit (231 before)
  • After the page-overlap commit, vp check, vp run check:types (35/35) and vp test run packages/deploy-cloudflare packages/deploy-core packages/void/test/unit were re-run: 10069 passed, 17 failed. The 17 are init.test.ts (16) and nitro.test.ts (1), which also fail on the commit before this one in the same shell.
  • vp check: no warnings, lint errors or type errors
  • vp run check:types: 35/35 successful
  • vp run test:all: 92 of 93 tasks passed. The one failing task was platform-api-integration-threads, 12 tests, because Playwright's Chromium was not installed. After playwright install chromium the six failing files passed (204 tests).
  • No user-facing documentation changes: this is an internal retry window.

Cloudflare's Worker version list can trail a write by minutes. Before the
upload, wait while the list lacks the active version. After the upload, wait
while the list still equals the baseline, on a schedule of about 5.5 minutes
instead of 250 ms and 500 ms. Failed reads keep their two quick retries.

Refs voidzero-dev#891

@0froq 0froq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked into this and commented

for (
let attempt = 0;
previous.versionId !== null &&
recent !== null &&

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The waits only continue while the read succeeded. A versions.list whose two pages disagree returns a non-zero status, which readRecentCloudflareVersionIds turns into null. That case gets 0 waits before the upload and only the 250/500 ms retries after it. Page 2 is only read above 10 versions, so this is the shape of the 20:08 inheritance-source-unavailable report in #891, not the stale-but-readable shape this fixes.

Not a regression, but "Fixes #891 for the version-list paths" would close the issue with that symptom unchanged. Either classify the page-overlap failure and retry it on this schedule, or narrow the claim.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c348401. cf-version-runner.ts now marks the page-overlap failure ("version history changed during inspection") as failure: 'version-history-changed'. activateCloudflareVersion retries that failure on STALE_VERSION_HISTORY_DELAYS_MS both before the upload and after it. If the overlap outlasts the schedule it still ends in inheritance-source-unavailable. Other failed reads are unchanged: no wait before the upload, two quick retries after it. Tests cover recover, exhausted and a different failure, before and after the upload, plus the runner marker. The PR body now lists the overlap case. triggers-failed is still untouched.

* Waits between reads of Cloudflare's Worker version list while it lags behind a write.
* Defaults to {@link STALE_VERSION_HISTORY_DELAYS_MS}.
*/
versionHistoryRetryDelaysMs?: ReadonlyArray<number>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STALE_VERSION_HISTORY_DELAYS_MS is this option's documented default but is not exported from src/index.ts, so a caller that wants to extend the schedule has to copy the array. Add it to the ./version.ts export list next to activateCloudflareVersion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c348401. STALE_VERSION_HISTORY_DELAYS_MS is now exported from src/index.ts next to activateCloudflareVersion.

The version list reads page 2 only above 10 versions. If a write lands
between the two page reads, the pages overlap and the read fails. That
failure ended the pre-upload check with no wait and left only two quick
retries after the upload.

The runner now marks this failure as version-history-changed, and both
waits retry it on the same schedule as a stale list. Other failures keep
their behavior, and an overlap that outlasts the schedule still stops
with inheritance-source-unavailable. Export
STALE_VERSION_HISTORY_DELAYS_MS from the package entry.

Refs voidzero-dev#891
@0froq

0froq commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

in packages/void/src/cli/cloudflare-process.ts:65

!['not-found', 'durable-migration', 'containers-unavailable'].includes(envelope.failure))

should include 'version-history-changed'. Not reachable today (the cf runner is in-process), but the whitelist and the failure union in execute.ts should stay in sync.

Thank you!

@cpojer

cpojer commented Nov 23, 2026

Copy link
Copy Markdown
Member

Slop review:

[P2] A rollback during either wait can break the next deploy. Void saves the uploaded candidate against the previously active version, then detects the rollback and aborts. Production traffic stays on the rollback version, but the next attempt uploads another candidate and fails because the saved receipt names the wrong parent. Recheck the active deployment before uploading after a pre-upload wait and before saving the receipt after a post-upload wait. Post-upload retry loop
[P2] A valid rollback can add 5½ minutes to an otherwise successful deploy. Cloudflare supports rolling back beyond the ten versions Void lists. In a direct deploy with no remote secrets, the base proceeded immediately. The PR waited 331.75 seconds before proceeding because the active version could never appear in that list. Compare the active version number with the list’s range before deciding to wait. Pre-upload retry condition · Cloudflare rollback limits

The process envelope decoder accepted only three of the four runner
failures, so a version-history-changed envelope from a child process
would have been rejected as invalid. The cf runner is in-process today,
so this path was not reachable.

The accepted failures are now a record keyed by the
CloudflareCommandResult failure union, so a failure added to the union
fails the typecheck until it is accepted here too.

Refs voidzero-dev#891
@konaito

konaito commented Nov 23, 2026

Copy link
Copy Markdown
Author

Fixed in f72b076. decodeCloudflareOperationResult in cloudflare-process.ts now accepts version-history-changed; it was the only value missing from the whitelist. The accepted failures are now a Record keyed by CloudflareCommandResult['failure'], so a value added to the union in execute.ts fails the typecheck until it is added here too. A test checks that each of the four failures decodes from the envelope.

A rollback during either version list wait was not seen until after
the candidate receipt was saved with the old active version as its
parent. The deploy then stopped, and the next deploy failed on that
receipt. After a wait, production is now read again before the upload
and before the receipt is saved. If it changed, the deploy stops with
deployment-changed and saves no receipt.

A rollback to a version older than the ten listed versions can never
appear in the list, but the pre-upload check waited the whole schedule
for it. The active version's number is now read with versions.view,
and the deploy waits only when that number is not below the list's
lowest number. A number that cannot be read keeps the wait.

Refs voidzero-dev#891
@konaito

konaito commented Nov 23, 2026

Copy link
Copy Markdown
Author

Fixed in e4fbe90.

Rollback during a wait. After the pre-upload wait, activateCloudflareVersion reads deployments status again before it uploads. After the post-upload wait, it reads it again before recordVerifiedCandidate. If production no longer matches the version read at the start, the deploy stops with deployment-changed and saves no receipt, so the next deploy does not find a receipt with the wrong parent. The re-read happens only after a wait. A test rolls production back inside sleep, before and after the upload, and checks that recordVerifiedCandidate is never called and that nothing is uploaded in the pre-upload case.

The same hazard exists on main for a rollback during the readiness probe, because the receipt is saved before readiness. This PR does not change that.

Rollback beyond the listed versions. This applies to the pre-upload wait only. The post-upload wait compares against the pre-upload baseline and does not look for the active version. When the list does not contain the active version, the deploy now reads that version once with versions.view and waits only if its number is not below the list's lowest number. An older active version proceeds at once, as on main. If the number cannot be read (a failed or thrown read, or no integer number; the API marks the field optional), the deploy still waits. A version the list trails may not be readable by id yet either. Skipping the wait in that case would bring back the failure this PR fixes, and the wait is bounded. A test with ten listed versions and an older active version expects no wait. Failed, thrown and unnumbered reads still expect the full schedule.

@cpojer
cpojer requested a review from Brooooooklyn November 23, 2026 07:46

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I'd like a review by @Brooooooklyn before we merge.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloudflare deploy stops on a lagging Worker version list (inheritance-source-changed, triggers-failed)

3 participants